<template>
  <div>
    <!-- 供应商维护 -->
    供应商联系人: <el-input style="width: 150px;" v-model="gyslxr" placeholder="请输入供应商联系人"></el-input>
    <el-button type="primary" icon="el-icon-search" @click="chaxun()"></el-button>
    <!-- <el-button type="primary" @click="chaxun()">查询</el-button> -->

    <el-button type="primary" @click="dialogVis()" style="margin-left: 1000px;">新增供应商</el-button>
    <el-dialog title="供应商维护" :visible.sync="dialogVisible" width="30%">
      <span>供应商名称:</span>
      <el-input v-model="purrish.supplierName1" placeholder="请输入供应商名称" style="width: 300px;"></el-input><br><br>
      <span>供应商地址:</span>
      <el-input v-model="purrish.address1" placeholder="请输入供应商地址" style="width: 300px;"></el-input><br><br>
      <span>联系人姓名:</span>
      <el-input v-model="purrish.contactName1" placeholder="请输入联系人姓名" style="width: 300px;"></el-input><br><br>
      <span>座&nbsp;&nbsp;&nbsp;机&nbsp;&nbsp;&nbsp;&nbsp;号:</span>
      <el-input v-model="purrish.contactTelephone1" placeholder="请输入座机号" style="width: 300px;"></el-input><br><br>
      <span>手&nbsp;&nbsp;&nbsp;机&nbsp;&nbsp;&nbsp;&nbsp;号:</span>
      <el-input v-model="purrish.contactMobile1" placeholder="请输入手机号" style="width: 300px;"></el-input><br><br>
      <span>银&nbsp;行&nbsp;账&nbsp;&nbsp;号:</span>
      <el-input v-model="purrish.bankAccount1" placeholder="请输入银行账号" style="width: 300px;"></el-input><br><br>
      <!-- <span>创&nbsp;建&nbsp;日&nbsp;&nbsp;期:</span>
      <el-input type="date" v-model="purrish.createTime1" placeholder="请输入创建日期" style="width: 300px;"></el-input> -->
      <span slot="footer" class="dialog-footer">
        <!-- <el-button @click="dialogVisible = false">取 消</el-button> -->
        <el-button type="primary" @click="quding()">确 定</el-button>
      </span>
    </el-dialog>
    <el-table :data="tableData" style="width: 100%; margin-top: 30px;">
      <el-table-column prop="sid" label="序号">
      </el-table-column>
      <el-table-column prop="supplierName" label="供应商">
      </el-table-column>
      <el-table-column prop="contactName" label="联系人">
      </el-table-column>
      <el-table-column prop="contactTelephone" label="座机">
      </el-table-column>
      <el-table-column prop="contactMobile" label="手机">
      </el-table-column>
      <el-table-column prop="bankAccount" label="银行帐号">
      </el-table-column>
      <el-table-column prop="address" label="地址">
      </el-table-column>
      <el-table-column prop="createTime" label="创建日期">

        <!-- 时间格式 -->
        <template slot-scope="sc">
          {{ new Date(sc.row.createTime *1000).toLocaleDateString ()}}
        </template>


      </el-table-column>
      <el-table-column prop="chaozuo" label="操作">

        <!-- scc代表表格 -->
        <template slot-scope="scc">
          <el-button type="primary" @click="xiugai(scc.row)" style="width: 60px;">修改</el-button>
          <!-- 表格的当前行 -->
          <el-button type="danger" @click="shanchu(scc.row.sid)" style="width: 60px;">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 修改 -->

    <el-dialog title="供应商修改" :visible.sync="dialogTableVisible" width="30%">
      <span>供应商名称:</span>
      <el-input v-model="purrish.supplierName1" placeholder="请输入供应商名称" style="width: 300px;"></el-input><br><br>
      <span>供应商地址:</span>
      <el-input v-model="purrish.address1" placeholder="请输入供应商地址" style="width: 300px;"></el-input><br><br>
      <span>联系人姓名:</span>
      <el-input v-model="purrish.contactName1" placeholder="请输入联系人姓名" style="width: 300px;"></el-input><br><br>
      <span>座&nbsp;&nbsp;&nbsp;机&nbsp;&nbsp;&nbsp;&nbsp;号:</span>
      <el-input v-model="purrish.contactTelephone1" placeholder="请输入座机号" style="width: 300px;"></el-input><br><br>
      <span>手&nbsp;&nbsp;&nbsp;机&nbsp;&nbsp;&nbsp;&nbsp;号:</span>

      <el-input v-model="purrish.contactMobile1" placeholder="请输入手机号" style="width: 300px;"></el-input><br><br>
      <span>银&nbsp;行&nbsp;账&nbsp;&nbsp;号:</span>
      <el-input v-model="purrish.bankAccount1" placeholder="请输入银行账号" style="width: 300px;"></el-input><br><br>
      <span>创&nbsp;建&nbsp;日&nbsp;&nbsp;期:</span>
      <el-input type="date" v-model="purrish.createTime1" placeholder="请输入创建日期" style="width: 300px;"></el-input>
      <span slot="footer" class="dialog-footer">
        <!-- <el-button @click="dialogVisible = false">取 消</el-button> -->
        <el-button type="primary" @click="queding()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  name: "gys",
  data() {
    return {
      gyslxr: "",
      purrish: {
        sid1: "",
        supplierName1: "",
        address1: "",
        contactName1: "",
        contactTelephone1: "",
        contactMobile1: "",
        bankAccount1: "",
        createTime1: "",
      },
      formData: [],
      dialogVisible: false,
      dialogTableVisible: false,

      tableData: []
    }
  },
  methods: {
    handleClose(done) {

    },

    /**
     * 添加
     */
    quding() {

      this.$confirm('确认添加？')
        .then(_ => {
          
          let formdata= new FormData()
          formdata.append("supplierName",this.purrish.supplierName1)
          formdata.append("contactName",this.purrish.contactName1)
          formdata.append("contactTelephone",this.purrish.contactTelephone1)
          formdata.append("contactMobile",this.purrish.contactMobile1)
          formdata.append("bankAccount",this.purrish.bankAccount1)
          formdata.append("address",this.purrish.address1)
          // formdata.append("createTime",this.purrish.createTime1)
          axios({
            url: "http://127.0.0.1:8686/api/Suppliertianjia",
            method: "post",
            data: formdata
          }).then((re) => {
            if (re.data) {
              this.dialogVisible = false
              alert("添加成功")
              this.one()
              this.purrish.supplierName1 = ""
              this.purrish.address1 = ""
              this.purrish.contactName1 = ""
              this.purrish.contactTelephone1 = ""
              this.purrish.contactMobile1 = ""
              this.purrish.bankAccount1 = ""
              // this.purrish.createTime1 = ""
            } else {
              alert("失败")
            }

          })
        })
        .catch(_ => {
        });
    },
    dialogVis() {
      this.dialogVisible = true
      this.purrish.supplierName1 = ""
      this.purrish.address1 = ""
      this.purrish.contactName1 = ""
      this.purrish.contactTelephone1 = ""
      this.purrish.contactMobile1 = ""
      this.purrish.bankAccount1 = ""
      this.purrish.createTime1= ""

    },

    /**
   * 删除
   */
    shanchu(sid) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        axios({
            url: "http://127.0.0.1:8686/api/Suppliershanchu",
            method: "get",
            params: {sid:sid}
          }).then((re) => {
            if (re.data) {
                    this.$message({
                type: 'success',
                message: '删除成功!'
              });
              this.one()
            } else {
              alert("删除失败")
            }
          })


       
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
      // .then(_ => {

      // axios({
      //   url: "http://127.0.0.1:8686/api/Suppliershanchu",
      //   method: "get",
      //   params: {sid:sid}
      // }).then((re) => {
      //   if (re.data) {
      //     // alert("删除成功")

      //     this.one()
      //   } else {
      //     alert("删除失败")
      //   }
      // })

    },
    /**
     * 修改供应商
     */
    xiugai(e) {
      this.dialogTableVisible = true;
      // this.purrish = e
      this.purrish.sid1=e.sid
      this.purrish.supplierName1 = e.supplierName
      this.purrish.address1 = e.address
      this.purrish.contactName1 = e.contactName
      this.purrish.contactTelephone1 = e.contactTelephone
      this.purrish.contactMobile1 = e.contactMobile
      this.purrish.bankAccount1 =e.bankAccount
      this.purrish.createTime1 = new Date(e.createTime*1000).toLocaleDateString()          
    },
    queding() {
      this.$confirm('确认修改？')
        .then(_ => {
          let formData = new FormData();
          formData.append("sid", this.purrish.sid1);
          formData.append("supplierName", this.purrish.supplierName1);
          formData.append("address", this.purrish.address1);
          formData.append("contactName", this.purrish.contactName1);
          formData.append("contactTelephone", this.purrish.contactTelephone1);
          formData.append("contactMobile", this.purrish.contactMobile1);
          formData.append("bankAccount", this.purrish.bankAccount1);
          formData.append("createTime", this.purrish.createTime1);
          axios({
            url: "http://127.0.0.1:8686/api/Supplierxiugai",
            method: "post",
            data: formData
          }).then((re) => {
            if (re.data) {
              this. dialogTableVisible = false,
              alert("修改成功")
              this.one()
            } else {
              alert("修改失败")
            }
          })
            .catch(_ => { });

        })
        .catch(_ => { });
    },
    /**
     * 查询
     */
    chaxun() {
      axios({
        url: "http://127.0.0.1:8686/api/Supplierchaxun",
        method: "get",
        params: { contactName: this.gyslxr }
      }).then((re) => {
        this.tableData = re.data
      })
    },
    /**
     * 把显示字段页面包起来
     */
    one() {

      axios({
        url: "http://127.0.0.1:8686/api/Suoolierxianshi",
        method: "get"
      }).then((re) => {
        this.tableData = re.data
        console.log(re)

      })
    }
  },
  mounted() {
    /**
     * 显示字段
     * 
     */
    this.one()


  },


}
</script>

<style></style>